import Mock from 'mockjs'

let arrayData = ['姓名', '性别', '常驻城市', "年龄", 'N', '职位']
let paramCorrel = []

// 查询
const query = {
  url: '/prod-api/safeguard/parameter/query',    // 请求地址
  method:'post',
  response:({ body })=>{
    console.log(body, 'body')
    let list = []
    for(let i=0; i < body.pageSize; i++) {
      const ramdowNum = Math.ceil(Math.random() * 2 + 1)
      paramCorrel = arrayData.slice(ramdowNum, arrayData.length)
      list.push(
        Mock.mock({
          paramId: Math.ceil(Math.random() * 100),
          param: body.parameter || Mock.Random.cword(2, 10),
          'paramType|1': ['输入型参数', '配置型参数', '计算型参数'],  // 随机选取数组里1个数据
          'paramCorrel': paramCorrel,
          paramCode: Math.random() > 0.5 ? 'Y' : 'N',
        })
      )    
    }

    return {
      data:list,
      total:50,
      code: 200
    } 
  },
}
// 添加
const add = {
  url: '/prod-api/safeguard/parameter/add',    // 请求地址
  method:'post',
  response:({ body })=>{
    arrayData.push(body.paramCorrel)
    return {
      data: {
        param: body.param,
        paramType: body.paramType,
        paramCorrel: body.paramCorrel,
        paramCode: body.paramCode,
      },
      msg: '',
      code: 200
    } 
  }
}

const defineQuery = {
  url: '/prod-api/safeguard/parameter/correldefine/query',    // 请求地址
  method:'post',
  response:({ body })=>{
    let list = []
    for(let i= 0; i < paramCorrel.length; i++ ){
      list.push({
        correl: paramCorrel[i], 
        type: Math.random() > 0.5 ? '1' : '2'
      })
    }
    return {
      data: list,
      msg: '',
      code: 200
    } 
  }
}

const defineSave = {
  url: '/prod-api/safeguard/parameter/correldefine/save',    // 请求地址
  method:'post',
  response:({ body })=>{
    return {
      data: body.data,
      msg: '保存成功',
      code: 200
    } 
  }
}

export default [ query, add, defineQuery, defineSave]